import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
// import a from '../views/home/a.vue'
import NProgress from "nprogress";
import "nprogress/nprogress.css";
let originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

//  处理路由替换的警告提示问题
let originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function push(location) {
  return originalReplace.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
    children: [
      {
        path: "/home/a",
        // component: a
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/home/a.vue"),
      },
      {
        path: "/home/table",
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/home/table.vue"),
      },
    ],
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, from, next) => {
  NProgress.start();
  console.log(to, from);
  next();
});
router.afterEach((to, from) => {
  console.log(to, from);
  NProgress.done();
});
export default router;
